home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!wemccaug
- From: wemccaug@prairienet.org (Wendy E. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: friend functions and access to private variables...
- Date: 16 Mar 1996 02:20:08 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4id8go$12q@vixen.cso.uiuc.edu>
- References: <4hogra$gnn@nntp.ucs.ubc.ca> <4ho95g$hjq@ccshst05.cs.uoguelph.ca>
- Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, jamesdf@unixg.ubc.ca (James Fairweather) says:
-
- >>I'm dealing with two classes, where a member function of class A is declared as
- >>a friend function of class B.
- >
- >>Unfortunately this does not allow the friend function access to private variables in
- >>class B...what gives? Is it not legal to make such a declaration?
- >
- >Heh, you have it backwards. To allow class A to access B's private
- >members, put friend class _A_; in B's header.
- >
- > James
- >
- >
- Mr. Fairweather says (in effect):
-
- class A { public: ...
- void memfunc(); // is the member-function in question
-
- How could A's members invite themselves to be friends of B: class
- B has to extend that invitation. All class A can do is declare some
- other function or class to be a friend of it. So it is not legal
- to make such a declaration.
-
- As to the first respondent, it did not appear that Mr. Fair-
- weather wanted all of class A to have access to B's private part,
- only one member function, so in class B's specification
- you want to include something like: friend void A::memfunc().
-
- wem
-
-